package com.esender.userpoints.listener;

import com.esender.userpoints.config.RabbitMQConfig;
import com.esender.userpoints.service.UserPointsConsume;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class UserPointsListener {
    @Autowired
    private UserPointsConsume userPointsConsume;
    @RabbitListener(queues = RabbitMQConfig.USER_POINTS_QUEUE)
    public void receiveMessage(String msg, Channel channel, Message message) throws InterruptedException, IOException {
        // 预扣除优惠券
        userPointsConsume.consume(message);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
